function [var1,var2,difvar,difc]=checkmodels(funcmod1,funcmod2,fullp1,varargin)
% =========================================================================
% function
% [var1,var2,difvar,difc]=checkmodels(funcmod1,funcmod2,fullp1,varargin)
% CHECKMODELS.m 
% Use to compare the implied variance of two models 
% E.g. debugging estimations vs. observation codes 
% 
% Input
% -----
% Pass function handle for two models 
% and either 1) fullp1 which will be used for both models or 
%            2) fullp1 + fullp2 which will be used for the first and second
%            model respectively 
% Solve each model and compute the variance of the observables and see how 
% different they are. 
% 
% Output: 
% VAR1:   Variance first model 
% VAR2:   Variance 2nd   model 
% DIFVAR  Differences in variances 
% DIFC    Differences in constant for observation equation 
% 
% Alejandro Justiniano Feb 10 2009
% =========================================================================
if nargin <3; error('Need Handle1,Handle2 and FULLP'); end 
if nargin == 3; flag_difcoef=0; disp('Single FULLP'); end; 
if nargin == 4; flag_difcoef=1; disp('Two FULLP'); end; 
[GG1,CC1,RR1,eu,SDX1,ZZ1]=feval(funcmod1,fullp1);    
varst1=disclyap_fast(GG1,RR1*(SDX1'*SDX1)*(RR1')); 
var1=ZZ1*(varst1)*(ZZ1'); 
if flag_difcoef==0
    [GG2,CC2,RR2,eu,SDX2,ZZ2]=feval(funcmod2,fullp1);
else
    [GG2,CC2,RR2,eu,SDX2,ZZ2]=feval(funcmod2,varargin{1});
end 
varst2=disclyap_fast(GG2,RR2*(SDX2'*SDX2)*(RR2')); 
var2=ZZ2*varst2*(ZZ2'); 
difvar=comparemat(var1,var2);     
difc  =max(abs( ZZ1*CC1 - ZZ2*CC2 )); 
if difc > 0.001; error('Differences in constants'); end; 